import { http } from "@/utils/http";
import { baseUrlApi } from "@/api/utils";
import { message } from "@/utils/message";
type Result = {
  current_page: number;
  result?: any;
  per_page?: number;
  total?: number;
  data?: any;
  resultTree?: any;
};
type ResultCreate = {
  code?: any;
  msg?: any;
  result?: {
    code?: any;
    msg?: any;
  };
};
/** 列表 */
export const getDeptTree = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/department/listTree", {
    params
  });
};
/** 创建 */
export const create = (data?: object) => {
  return http
    .request<ResultCreate>("post", baseUrlApi + "/department/store", {
      data
    })
    .catch(error => {
      message(error.response.data.msg ?? "操作失败,请联系管理员", {
        type: "error"
      });
    });
};
/** 修改 */
export const update = (data?: object) => {
  return http
    .request<ResultCreate>("put", baseUrlApi + "/department/update", {
      data
    })
    .catch(error => {
      message(error.response.data.msg ?? "操作失败,请联系管理员", {
        type: "error"
      });
    });
};
/** 删除 */
export const del = (data?: object) => {
  return http
    .request<ResultCreate>("delete", baseUrlApi + "/department/delete", {
      data
    })
    .catch(error => {
      message(error.response.data.msg ?? "操作失败,请联系管理员", {
        type: "error"
      });
    });
};
